//
//  SPPolyline.m
//  SPMapKit
//
//  Created by zhangbo on 2017/9/9.
//  Copyright © 2017年 zhangbo. All rights reserved.
//

#import "SPPolyline.h"

@implementation SPPolyline

-(instancetype) init
{
    self = [super init];
    if (self) {
        self.gpspointList = [[NSMutableArray alloc] init];
    }
    
    return self;
}

-(void) addGPSPoint:(CLLocationCoordinate2D) point
{
    CGPoint p;
    p.x = point.latitude;
    p.y = point.longitude;
    
    if ([_gpspointList count] == 0) {
        _mapRect.origin = p;
    }else{
        if (p.x < _mapRect.origin.x) {
            _mapRect.size.width += (_mapRect.origin.x - p.x);
            _mapRect.origin.x = p.x;
        }else{
            if (p.x - _mapRect.origin.x > _mapRect.size.width) {
                _mapRect.size.width = p.x - _mapRect.origin.x;
            }
        }
        
        if (p.y < _mapRect.origin.y) {
            _mapRect.size.height += (_mapRect.origin.y - p.y);
            _mapRect.origin.y = p.y;
        }else{
            if (p.y - _mapRect.origin.y > _mapRect.size.height) {
                _mapRect.size.height = p.y - _mapRect.origin.y;
            }
        }
    }
    
    [_gpspointList addObject:[NSValue valueWithCGPoint:p]];
}

-(CGRect) mapRect
{
    return _mapRect;
}

@end

@implementation SPSingleLine

-(instancetype) initWithPoints:(CLLocationCoordinate2D) p0 p1:(CLLocationCoordinate2D) p1
{
    self = [super init];
    if (self) {
        self.p0 = p0;
        self.p1 = p1;
    }
    
    return self;
}

@end

@implementation SPPolygon

@end

@implementation SPCircle

@end
